home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 October: Mac OS SDK / Dev.CD Oct 00 SDK1.toast / Development Kits / Cross Platform / QuickTime 4.1.2 Windows SDK / CIncludes / Serial.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-12  |  9.9 KB  |  310 lines  |  [TEXT/R*ch]

  1. /*
  2.      File:        Serial.h
  3.  
  4.      Contains:    Asynchronous Serial Driver (.AIn/.AOut/.BIn/.BOut) Interfaces
  5.  
  6.      Version:    Technology:    System 7.6+
  7.                  Release:    QuickTime 4.1
  8.  
  9.      Copyright:    (c) 1985-1999 by Apple Computer, Inc., all rights reserved
  10.  
  11.      Bugs?:        For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. */
  17. #ifndef __SERIAL__
  18. #define __SERIAL__
  19.  
  20. #ifndef __MACTYPES__
  21.     #include <MacTypes.h>
  22. #endif
  23.  
  24.  
  25.  
  26.  
  27. #if PRAGMA_ONCE
  28. #pragma once
  29. #endif
  30.  
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34.  
  35. #if PRAGMA_IMPORT
  36. #pragma import on
  37. #endif
  38.  
  39. #if PRAGMA_STRUCT_ALIGN
  40.     #pragma options align=mac68k
  41. #elif PRAGMA_STRUCT_PACKPUSH
  42.     #pragma pack(push, 2)
  43. #elif PRAGMA_STRUCT_PACK
  44.     #pragma pack(2)
  45. #endif
  46.  
  47. enum {
  48.     baud150                        = 763,
  49.     baud300                        = 380,
  50.     baud600                        = 189,
  51.     baud1200                    = 94,
  52.     baud1800                    = 62,
  53.     baud2400                    = 46,
  54.     baud3600                    = 30,
  55.     baud4800                    = 22,
  56.     baud7200                    = 14,
  57.     baud9600                    = 10,
  58.     baud14400                    = 6,
  59.     baud19200                    = 4,
  60.     baud28800                    = 2,
  61.     baud38400                    = 1,
  62.     baud57600                    = 0
  63. };
  64.  
  65. enum {
  66.     stop10                        = 16384,
  67.     stop15                        = -32768L,
  68.     stop20                        = -16384
  69. };
  70.  
  71. enum {
  72.     noParity                    = 0,
  73.     oddParity                    = 4096,
  74.     evenParity                    = 12288
  75. };
  76.  
  77. enum {
  78.     data5                        = 0,
  79.     data6                        = 2048,
  80.     data7                        = 1024,
  81.     data8                        = 3072
  82. };
  83.  
  84. enum {
  85.     aData                        = 6,                            /* channel A data in or out (historical) */
  86.     aCtl                        = 2,                            /* channel A control (historical) */
  87.     bData                        = 4,                            /* channel B data in or out (historical) */
  88.     bCtl                        = 0                                /* channel B control (historical) */
  89. };
  90.  
  91. enum {
  92.     dsrEvent                    = 2,                            /* flag for SerShk.evts */
  93.     riEvent                        = 4,                            /* flag for SerShk.evts */
  94.     dcdEvent                    = 8,                            /* flag for SerShk.evts */
  95.     ctsEvent                    = 32,                            /* flag for SerShk.evts */
  96.     breakEvent                    = 128                            /* flag for SerShk.evts */
  97. };
  98.  
  99. enum {
  100.     xOffWasSent                    = 128,                            /* flag for SerStaRec.xOffSent */
  101.     dtrNegated                    = 64,                            /* flag for SerStaRec.xOffSent */
  102.     rtsNegated                    = 32                            /* flag for SerStaRec.xOffSent */
  103. };
  104.  
  105. enum {
  106.     ainRefNum                    = -6,                            /* serial port A input */
  107.     aoutRefNum                    = -7,                            /* serial port A output */
  108.     binRefNum                    = -8,                            /* serial port B input */
  109.     boutRefNum                    = -9                            /* serial port B output */
  110. };
  111.  
  112. enum {
  113.     swOverrunErr                = 1,                            /* serial driver error masks */
  114.     breakErr                    = 8,                            /* serial driver error masks */
  115.     parityErr                    = 16,                            /* serial driver error masks */
  116.     hwOverrunErr                = 32,                            /* serial driver error masks */
  117.     framingErr                    = 64                            /* serial driver error masks */
  118. };
  119.  
  120. enum {
  121.     kOptionPreserveDTR            = 128,                            /* option bit used with Control code 16 */
  122.     kOptionClockX1CTS            = 64                            /* option bit used with Control code 16 */
  123. };
  124.  
  125. enum {
  126.     kUseCTSOutputFlowControl    = 128,                            /* flag for SerShk.fCTS */
  127.     kUseDSROutputFlowControl    = 64,                            /* flag for SerShk.fCTS */
  128.     kUseRTSInputFlowControl        = 128,                            /* flag for SerShk.fDTR */
  129.     kUseDTRInputFlowControl        = 64                            /* flag for SerShk.fDTR */
  130. };
  131.  
  132. enum {
  133.     sPortA                        = 0,                            /* Macintosh modem port */
  134.     sPortB                        = 1,                            /* Macintosh printer port */
  135.     sCOM1                        = 2,                            /* RS-232 port COM1 */
  136.     sCOM2                        = 3                                /* RS-232 port COM2 */
  137. };
  138.  
  139. typedef SInt8                             SPortSel;
  140. /* csCodes for serial driver Control routines */
  141. enum {
  142.     kSERDConfiguration            = 8,                            /* program port speed, bits/char, parity, and stop bits */
  143.     kSERDInputBuffer            = 9,                            /* set buffer for chars received with no read pending */
  144.     kSERDSerHShake                = 10,                            /* equivalent to SerHShake, largely obsolete */
  145.     kSERDClearBreak                = 11,                            /* assert break signal on output */
  146.     kSERDSetBreak                = 12,                            /* negate break state on output */
  147.     kSERDBaudRate                = 13,                            /* set explicit baud rate, other settings unchanged */
  148.     kSERDHandshake                = 14,                            /* superset of 10, honors setting of fDTR */
  149.     kSERDClockMIDI                = 15,                            /* clock externally on CTS with specified multiplier */
  150.     kSERDMiscOptions            = 16,                            /* select clock source and DTR behavior on close */
  151.     kSERDAssertDTR                = 17,                            /* assert DTR output */
  152.     kSERDNegateDTR                = 18,                            /* negate DTR output */
  153.     kSERDSetPEChar                = 19,                            /* select char to replace chars with invalid parity */
  154.     kSERDSetPEAltChar            = 20,                            /* select char to replace char that replaces chars with invalid parity */
  155.     kSERDSetXOffFlag            = 21,                            /* set XOff output flow control (same as receiving XOff) */
  156.     kSERDClearXOffFlag            = 22,                            /* clear XOff output flow control (same as receiving XOn) */
  157.     kSERDSendXOn                = 23,                            /* send XOn if input flow control state is XOff */
  158.     kSERDSendXOnOut                = 24,                            /* send XOn regardless of input flow control state */
  159.     kSERDSendXOff                = 25,                            /* send XOff if input flow control state is XOn */
  160.     kSERDSendXOffOut            = 26,                            /* send XOff regardless of input flow control state */
  161.     kSERDResetChannel            = 27,                            /* reset serial I/O channel hardware */
  162.     kSERDHandshakeRS232            = 28,                            /* extension of 14, allows full RS-232 hardware handshaking */
  163.     kSERDStickParity            = 29,                            /* use mark/space parity */
  164.     kSERDAssertRTS                = 30,                            /* assert RTS output */
  165.     kSERDNegateRTS                = 31,                            /* negate RTS output */
  166.     kSERD115KBaud                = 115,                            /* set 115.2K baud data rate */
  167.     kSERD230KBaud                = 230                            /* set 230.4K baud data rate */
  168. };
  169.  
  170.  
  171. /* csCodes for serial driver Status routines */
  172. enum {
  173.     kSERDInputCount                = 2,                            /* return characters available (SerGetBuf) */
  174.     kSERDStatus                    = 8,                            /* return characters available (SerStatus) */
  175.     kSERDVersion                = 9,                            /* return version number in first byte of csParam */
  176.     kSERDGetDCD                    = 256                            /* get instantaneous state of DCD (GPi) */
  177. };
  178.  
  179.  
  180.  
  181. struct SerShk {
  182.     Byte                             fXOn;                        /* XOn/XOff output flow control flag */
  183.     Byte                             fCTS;                        /* hardware output flow control flags */
  184.     unsigned char                     xOn;                        /* XOn character */
  185.     unsigned char                     xOff;                        /* XOff character */
  186.     Byte                             errs;                        /* errors mask bits */
  187.     Byte                             evts;                        /* event enable mask bits */
  188.     Byte                             fInX;                        /* XOn/XOff input flow control flag */
  189.     Byte                             fDTR;                        /* hardware input flow control flags */
  190. };
  191. typedef struct SerShk                    SerShk;
  192.  
  193. struct SerStaRec {
  194.     Byte                             cumErrs;                    /* errors accumulated since last SerStatus() call */
  195.     Byte                             xOffSent;                    /* input (requested to be) held off by xOffWasSent or dtrNegated or rtsNegated */
  196.     Byte                             rdPend;                        /* incomplete read pending in I/O queue */
  197.     Byte                             wrPend;                        /* incomplete write pending in I/O queue */
  198.     Byte                             ctsHold;                    /* transmit disabled by hardware handshaking */
  199.     Byte                             xOffHold;                    /* transmit disabled by XOn/XOff handshaking */
  200.     Byte                             dsrHold;                    /* transmit disabled: external device not ready */
  201.     Byte                             modemStatus;                /* reports modem status according to SerShk.evts */
  202. };
  203. typedef struct SerStaRec                SerStaRec;
  204. #if OLDROUTINENAMES
  205. /* ********************************************************************************************* */
  206. /* The following constant names have been retired in favor of standard, more descriptive names.  */
  207. /* You can still compile old code by defining OLDROUTINENAMES. There were several constants that */
  208. /* were formerly available that have been removed, as they are now regarded as either private or */
  209. /* unsupported. We advise that you stop using any constants that are not defined in this file.   */
  210. /* ********************************************************************************************* */
  211. enum {
  212.     serdOptionClockExternal        = kOptionClockX1CTS,            /* option bit used with Control code 16 */
  213.     serdOptionPreserveDTR        = kOptionPreserveDTR            /* option bit used with Control code 16 */
  214. };
  215.  
  216. /* csCodes for serial driver Control routines */
  217. enum {
  218.     serdReset                    = kSERDConfiguration,
  219.     serdSetBuf                    = kSERDInputBuffer,
  220.     serdHShake                    = kSERDSerHShake,
  221.     serdClrBrk                    = kSERDClearBreak,
  222.     serdSetBrk                    = kSERDSetBreak,
  223.     serdSetBaud                    = kSERDBaudRate,
  224.     serdHShakeDTR                = kSERDHandshake,
  225.     serdSetMIDI                    = kSERDClockMIDI,
  226.     serdSetMisc                    = kSERDMiscOptions,
  227.     serdSetDTR                    = kSERDAssertDTR,
  228.     serdClrDTR                    = kSERDNegateDTR,
  229.     serdSetPEChar                = kSERDSetPEChar,
  230.     serdSetPECharAlternate        = kSERDSetPEAltChar,
  231.     serdSetXOff                    = kSERDSetXOffFlag,
  232.     serdClrXOff                    = kSERDClearXOffFlag,
  233.     serdSendXOnConditional        = kSERDSendXOn,
  234.     serdSendXOn                    = kSERDSendXOnOut,
  235.     serdSendXOffConditional        = kSERDSendXOff,
  236.     serdSendXOff                = kSERDSendXOffOut,
  237.     serdChannelReset            = kSERDResetChannel,
  238.     serdSet230KBaud                = kSERD230KBaud                    /* set 230K baud data rate */
  239. };
  240.  
  241.  
  242. /* csCodes for serial driver Status routines */
  243. enum {
  244.     serdGetBuf                    = kSERDInputCount,
  245.     serdStatus                    = kSERDStatus,
  246.     serdGetVers                    = kSERDVersion
  247. };
  248.  
  249. #endif  /* OLDROUTINENAMES */
  250.  
  251. /*
  252.     The following interfaces are for the legacy high-level serial driver glue in
  253.     the interface libraries of your development system. They merely substitue for
  254.     the corresponding synchronous calls to PBControl and PBStatus.
  255.  
  256.     They have not been updated as the serial driver API has evolved. Take note:
  257.  
  258.         SerHShake does not support hardware input flow control. Use csCode 14.
  259.         SerStatus returns only the first six bytes of SerStaRec (through xOffHold).
  260. */
  261. EXTERN_API( OSErr )
  262. SerReset                        (short                     refNum,
  263.                                  short                     serConfig);
  264.  
  265. EXTERN_API( OSErr )
  266. SerSetBuf                        (short                     refNum,
  267.                                  Ptr                     serBPtr,
  268.                                  short                     serBLen);
  269.  
  270. EXTERN_API( OSErr )
  271. SerHShake                        (short                     refNum,
  272.                                  const SerShk *            flags);
  273.  
  274. EXTERN_API( OSErr )
  275. SerSetBrk                        (short                     refNum);
  276.  
  277. EXTERN_API( OSErr )
  278. SerClrBrk                        (short                     refNum);
  279.  
  280. EXTERN_API( OSErr )
  281. SerGetBuf                        (short                     refNum,
  282.                                  long *                    count);
  283.  
  284. EXTERN_API( OSErr )
  285. SerStatus                        (short                     refNum,
  286.                                  SerStaRec *            serSta);
  287.  
  288.  
  289.  
  290. #if PRAGMA_STRUCT_ALIGN
  291.     #pragma options align=reset
  292. #elif PRAGMA_STRUCT_PACKPUSH
  293.     #pragma pack(pop)
  294. #elif PRAGMA_STRUCT_PACK
  295.     #pragma pack()
  296. #endif
  297.  
  298. #ifdef PRAGMA_IMPORT_OFF
  299. #pragma import off
  300. #elif PRAGMA_IMPORT
  301. #pragma import reset
  302. #endif
  303.  
  304. #ifdef __cplusplus
  305. }
  306. #endif
  307.  
  308. #endif /* __SERIAL__ */
  309.  
  310.